package com.jinghong.registerlogin.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson2.JSON;
import com.jinghong.registerlogin.ai.V4OkHttpClientTest;
import com.jinghong.registerlogin.model.dto.PaperDTO;
import com.jinghong.registerlogin.model.pojo.*;
import com.jinghong.registerlogin.service.PaperQuestionService;
import com.jinghong.registerlogin.service.PaperService;
import com.jinghong.registerlogin.service.QuestionService;
import lombok.Generated;
import lombok.extern.java.Log;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.weaver.patterns.TypePatternQuestions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * ClassName:PaperMapper
 * Package:com.jinghong.registerlogin.controller
 * Description:
 * &#064;Author:  寻月君子
 * &#064;CreatTime:2024/5/22  15:18
 * Version:1.0
 *
 * @author hongy
 */
@Slf4j
@RestController
@RequestMapping("/paper")
public class PaperController {

    @Autowired
    private QuestionService questionService;

    @Autowired
    private PaperService paperService;

    @Autowired
    private PaperQuestionService paperQuestionService;



    @PostMapping
    public Result insertPaper(@RequestBody Paper paper) {
        paperService.generateAndInsertPaper(paper);
        return Result.success();
    }



    /**
     * 试卷分页查询展示
     *
     * @param page     页数
     * @param pageSize 页容量
     * @param topic    试卷标题
     * @param userId   试卷创建者
     * @param status   试卷状态
     * @param begin    试卷被创建的时间范围-开始时间
     * @param end      试卷被创建的时间范围-结束时间
     * @return pageBean(存放试卷集合)对象
     */
    @GetMapping
    public Result listPaper(@RequestParam(defaultValue = "1") Integer page,
                            @RequestParam(defaultValue = "10") Integer pageSize,
                            String subject, String topic, Integer userId, Integer status, @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime begin, @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime end) {
        PageBean pageBean = paperService.list(page, pageSize, subject, topic, userId, status, begin, end);
        return Result.success(pageBean);
    }


    @PutMapping("/updatePaperStatus")
    public Result updatePaperStatus(Integer id, Integer status) {
        log.info("用户发布试卷到平台或,取消发布到社区,试卷id:{},状态{}", id, status);
        paperService.updateStatus(id, status);
        return Result.success();
    }

}
